const { validationResult } = require('express-validator');

/**
 * 验证中间件
 * 检查请求中的验证错误并返回适当的响应
 */
exports.validate = (req, res, next) => {
  const errors = validationResult(req);
  
  if (!errors.isEmpty()) {
    return res.status(400).json({
      message: '验证失败',
      errors: errors.array().map(error => ({
        field: error.param,
        message: error.msg
      }))
    });
  }
  
  next();
}; 